import os

class Environment(object):
    def needs_compilation(self):
        return hasattr(self, 'compile')

    def exe_filename_for(self, filename):
        """
        Default implementation: Gets the name of the executable file that
        results from compiling filename.  Assumes that a subclass will set
        self.exe_suffix.  Should not be called if not self.needs_compilation().
        """
        return os.path.splitext(filename)[0] + self.exe_suffix

    def execute(self, filename):
        """
        Default implementation: if filename is a script, run it through the
        default binary, and if it needs compilation, then run its exe output.
        """
        if self.needs_compilation():
            self.host.popen_in_console(self.exe_filename_for(filename))
        else:
            self.host.popen_in_console([self.path, filename])
